package org.example.book.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 猪头
 */

@Data
@Schema(description = "统一返回结果类")
public class R<T> {

    @Schema(description = "状态码")
    private Integer code;
    @Schema(description = "返回信息")
    private String message;
    @Schema(description = "返回数据")
    private T data;

    //Success
    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.setCode(666);
        r.setMessage("操作成功");
        r.setData(data);
        return r;
    }
    public static R success() {
        R tr = new R<>();
        tr.setCode(666);
        tr.setMessage("操作成功");
        return tr;
    }

    //Error
    public static R error(Integer code, String message) {
        R tr = new R<>();
        tr.setCode(code);
        tr.setMessage("!ERROR!==!ERROR!"+message);
        return tr;
    }
}
